<?php
namespace Deployer;

require 'recipe/laravel.php';

set('application', 'ShixunWeb');
set('repository', 'https://gitee.com/subowen_admin/ShiXunWeb.git');
set('git_tty', true);
add('shared_files', []);
add('shared_dirs', []);
add('writable_dirs', []);
set('allow_anonymous_stats', false);
set('default_stage', 'local');

// Hosts
host('47.95.200.16')
    ->user('superwen')
    ->stage('prod')
    ->set('deploy_path', '/hwdata/www/ShixunWeb');

localhost()
    ->stage('local')
    ->roles('test', 'build');

desc('git push origin master');
task('git:push', function() {
    writeln('start git push task');
    run('git add .');
    run('git commit -m "auto commit by deploy to gitee"');
    run('git push origin master');
});

// Tasks
task('build', function () {
    run('cd {{release_path}} && build');
});

desc('Restart PHP-FPM service');
task('php-fpm:restart', function () {
    run('sudo systemctl restart php-fpm.service');
});

desc('Restart nginx service');
task('nginx:restart', function () {
    run('sudo systemctl restart nginx.service');
});

// [Optional] if deploy fails automatically unlock.
after('deploy:failed', 'deploy:unlock');
after('deploy:symlink', 'artisan:config:cache');
after('deploy:symlink', 'php-fpm:restart');
// after('deploy:symlink', 'nginx:restart');

// Migrate database before symlink new release.
//before('deploy:symlink', 'artisan:migrate');
// Can run 'dep list' to see taskes